<?php
class Adminlogin extends Base_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('adminuser_model');
    }

    public function index()
    {
        $post = $this->input->post();
        if(empty($post)){
            $cap = $this->getCaptcha();
            $data = array(
                'cssroot'=>base_url('html/admin/css/'),
                'jsroot'=>base_url('html/admin/js/'),
                'imgroot'=>base_url('html/admin/img/'),
                'posturl'=>site_url("admin/adminlogin/"),
                'redirecturl'=>site_url("admin/adminmain/"),
                'updatecapurl'=>site_url("admin/adminlogin/updateCap"),
                'captcha'=>$cap
            );
            $this->load->view('admin/login',$data);
        }else{
            $res = $this->adminuser_model->login($post);
            if ($res['code'] == 0){
                $this->error($res['msg']);
            }else{
                $this->adminuser_model->setSession($res['uid']);
                $this->success();
            }
        }

    }

    public function updateCap()
    {
        $cap = $this->getCaptcha();
        $this->success($cap);
    }

}